#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef double db;
inline LL read()
{
	LL x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=2e3+10,INF=0x3f3f3f3f;
LL n,head[MAXN*2],cnt,S,T,cost,flow,dis[MAXN*2];
bool vis[MAXN*2];
struct edge
{
	LL v,next,flow,cost;
}e[MAXN*MAXN*2];
void addedge(LL x,LL y,LL f,LL c)
{
	e[cnt]=(edge){y,head[x],f,c};
	head[x]=cnt++;
	swap(x,y);
	e[cnt]=(edge){y,head[x],0,-c};
	head[x]=cnt++;
	return;
}
LL aug(LL u,LL _min)
{
	vis[u]=true;
	if(u==T)
	{
		cost+=dis[S]*_min;
		flow+=_min;
		return _min;
	}
	LL ret=0,k;
	for(LL i=head[u];~i;i=e[i].next)
	{
		LL v=e[i].v;
		if(vis[v]||!e[i].flow||dis[v]-dis[u]+e[i].cost)continue;
		k=aug(v,min(_min-ret,e[i].flow));
		e[i].flow-=k;
		e[i^1].flow+=k;
		ret+=k;
		if(ret==_min)break;
	}
	return ret;
}
bool mdf()
{
	LL _min=INF;
	for(LL u=0;u<=2*n+1;++u)
	{
		if(!vis[u])continue;
		for(LL i=head[u];~i;i=e[i].next)
		{
			LL v=e[i].v;
			if(!e[i].flow||vis[v])continue;
			_min=min(_min,dis[v]-dis[u]+e[i].cost);
		}
	}
	if(_min==INF)return false;
	for(LL i=0;i<=2*n+1;++i)
		if(vis[i])
			dis[i]+=_min;
	return true;
}
void zkw()
{
	flow=cost=0;
	memset(dis,0,sizeof(dis));
	do do memset(vis,0,sizeof(vis));
	while(aug(S,INF));
	while(mdf());
	return;
}
int main()
{
	n=read();
	memset(head,-1,sizeof(head));
	T=2*n+1;
	for(LL i=1;i<=n;++i)
	{
		LL x=read();
		addedge(S,i,x,0);
		addedge(i+n,T,x,0);
	}
	LL p1=read(),t2=read(),p2=read(),t3=read(),p3=read();
	for(LL i=1;i<=n;++i)
	{
		if(i<n)addedge(i,i+1,INF,0);
		addedge(S,i+n,INF,p1);
		if(i+t2<=n)addedge(i,i+t2+n,INF,p2);
		if(i+t3<=n)addedge(i,i+t3+n,INF,p3);
	}
	zkw();
	printf("%lld\n",cost);
	return 0;
}
